package com.book.book.service;

import com.book.book.dao.NovelMapper;
import com.book.book.entity.Novel;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.HashMap;
import java.util.List;

/***
 * @Author Lin
 * @Date Create By 19:27 2017/10/9
 * @Description
 */
@Service("novelServiceImpl")
public class NovelServiceImpl implements NovelService {

    @Autowired
    private NovelMapper novelMapper;

    @Override
    public List<Novel> getNovelByKeyword(String keyword) {
        keyword = "%" + keyword + "%";
        return novelMapper.selectNovelByKeyword(keyword);
    }

    @Override
    public List<Novel> getNovelByKeywordAndPlatformId(String keyword, int platformId) {
        HashMap<String, String> map = new HashMap<>();
        map.put("keyword", "%" + keyword + "%");
        map.put("platformId", platformId + "");
        return novelMapper.selectNovelByKeywordAndPlatformId(map);
    }

    @Override
    @Transactional
    public void bacthNovel(List<Novel> novels) {
        novelMapper.batchInsert(novels);
    }
}
